<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>用户登录页面</title>
  <link rel="stylesheet" href="/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
  <script src="/js/jquery-3.7.1.min.js"></script>
  <script src="/js/bootstrap.js"></script>
  <style>
    /* 添加自定义样式 */
    body {
      background-color: gray;
      background-size: cover;
      background-repeat: no-repeat;
      font-family: Arial, sans-serif;
    }
    .container-fluid {
      background-color: rgba(255, 255, 255, 0.8); /* 半透明白色背景 */
      border-radius: 10px;
      padding: 20px;
    }
    h1 {
      text-align: center;
      color: tan;
    }
    label {
      font-weight: bold;
      color: #666;
    }
    input[type="text"], input[type="password"] {
      border-radius: 5px;
    }
    button {
      background-color: #007bff;
      color: white;
      transition: background-color 0.3s ease; /* 添加过渡效果 */
    }
    button:hover {
      background-color: red;
    }
    /* 添加响应式设计 */
    @media (max-width: 768px) {
      .container-fluid {
        width: 90%;
      }
    }
  </style>
  <link rel="stylesheet" href="/plugins/bootstraptable/bootstrap-table.js">
</head>

<body>
<!--登录界面-->
<div class="container-fluid">
  <h1>用户名密码登录</h1>
  <form>
    <label for="option">选择身份：</label>
    <select class="form-control" id="option" name="option">
      <option value="student">学生</option>
      <option value="teacher">教师</option>
      <option value="admin">管理员</option>
    </select>
    <div class="form-group">
      <label for="username">用户名：</label>
      <input type="text" class="form-control" id="username" name="username" placeholder="用户名">
    </div>
    <div class="form-group">
      <label for="password">密码：</label>
      <input type="password" class="form-control" id="password" name="password" placeholder="密码">
    </div>

    <button type="button" class="btn btn-primary" onclick="login();" style="width: 100%">登录</button>
  </form>
</div>
<!--操作-->
<script type="text/javascript">
  function login(){
    localStorage.setItem("username", $("#username").val());//为跨页面做准备
    var name=$("#username").val();
    var password=$("#password").val();
    if($("#option").val()=="student"){
      var flag=1;
    }else if($("#option").val()=="teacher"){
      var flag=2;
    }else{
      var flag=3;
    }
    $.ajax({
      url:"/webapi/login/user",
      data:{
        username:name,
        password:password,
        flag:flag//为了防止跨越表核对
      }
    }).done(function (rs){
      if(rs==1){
        window.location.href="/sc/sclist";//sc表
      }else if(rs==2) {
        window.location.href="/teacher/tlist";//teacher表
      }else if(rs==3) {
        window.location.href="/student/slist";//学生表/教师表/课程表
      }else{
        alert("用户名或密码不正确！");
      }
    })
  }
</script>

</body>
</html>